﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSharpDelegate实战
{
    // 【1】声明委托类型
    public delegate void ReceiveDelegate(string data);
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        //【2】编写具体方法
        private void ReceiveMsg(string data)
        {
            this.txtContent.Text += data + "\r\n";
        }

        private void btn_create_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < 4; i++) //创建3个子窗体
            {
                FrmChild frm = new FrmChild(i);
                frm.Show();

                //【4】关联委托变量和方法
                frm.ChildReceive += ReceiveMsg;
            }          
        }


        
    }
}
